
getCookie=function(name){
    var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr!=null)return unescape(arr[2]); return "";
}
var token= getCookie("token");
$(function(){
//	获取个人资料
	$.ajax({
        url:'http://ww.yc630.com/api/index.php/Buyer/User/userinfo',
        type:"post",
        data:{
            'token':token
        },
        dataType:"JSON",
        success:function(data){        	
            $('#name').val(data['data']['nickname']);
            $("#gr_name").html(data['data']['nickname'])
            if(data['data']['sex'] == 1){
            	$('#nan').attr('checked', 'checked');
            }else if(data['data']['sex'] == 2){
            	$('#nv').attr('checked', 'checked');
            }
            $('#phone').html(data['data']['username']);
            $('#email').html(data['data']['email']);
            var avatar = data['data']['avatar'];
            if(avatar==''){
            	avatar = '../img/Group%2019.png';
            }
            $('.grzl_wrap .photo img').attr('src',avatar);
            $("#gr_img").attr('src',avatar)
            $("#headPic").attr('src',avatar)
        }
    })
	
	//修改个人资料
	$('#user_commit').click(function(){
		var nickname = $('#name').val();
		var sex = $("input[name='sex']:checked").val();
		var avatar = $('.grzl_wrap .photo img').attr('src');
		
		
			$.ajax({
				url:'http://ww.yc630.com/api/index.php/Buyer/User/userinfoChange',
		        type:"post",
		        data:{'nickname':nickname, 'sex':sex,'avatar':avatar,'token':token},
		        dataType:"JSON",
		        success:function(data){
		        	alert('修改成功:)');
                    window.location.reload()
		        }
		})
		
	})
	

	 $("#file_upload").uploadify({	 
	 	
        'swf'           : '../uploadify/uploadify.swf',
        'uploader'      : 'http://ww.yc630.com/api/index.php/Seller/Seller/upload',      
        'width':62,
	    'height':30,
        'multi'         : true,
        'removeTimeout' : 0.2,//成功显示时间
        'fileTypeExts' : '*.jpg;*.png',
        'scriptAccess' : 'always',
        'onUploadSuccess' : function(file, data, response) {
            data=$.parseJSON(data);
          
        	$('.grzl_wrap .photo img').attr('src',data['data'][0]['image']);
           
        }


    });

	
		 

})
    
